package live.pay;


import java.util.Date;
import java.util.Map;
import java.util.TreeMap;


import org.apache.log4j.Logger;

import live.api.impl.PaySendReqRes;
import live.common.Format;
import live.common.Log4jXmlConfig;
import live.common.PostParam;
import live.cz.entity.Order;
import live.response.WebServicePay;

public class PayManager{
	WebServicePay wsp = new WebServicePay();
	Logger LOG = Log4jXmlConfig.getInstance().returnLogger(PayManager.class);
	/*
	 * 发送请求
	 */
	public void sendRequestMobiel(Order order,String service_id){
		Map<String, Object> map = new TreeMap<String, Object>();
		map.put("service_id", service_id);
		//发起方机构编码
		map.put("req_org_cd", "123456");
		//发起时间
		map.put("req_trans_tm", Format.getInstance().dateFormatString(new Date(), "yyyyMMddHHmmss"));
		//订单号
		map.put("req_trans_seq", String.valueOf(new Date().getTime()));
		map.put("order_id", order.getOrderid());
		map.put("seller_id", "12345");
		map.put("sub_order_flag", "N");
		map.put("sub_order_num", "0");
		map.put("sub_order_dtl", "");
		map.put("order_desc", mobileOrderDesc(order));
		map.put("tot_trans_amt", String.valueOf((int)(order.getSalePrice()*100)));
		map.put("buyer_id", "12345678");
		map.put("valid_date", "0");
		map.put("notify_url", PostParam.NOTIFY.toString());
		map.put("return_url", "");
		map.put("sign", SignUtil.sign(map,PostParam.PAYKEY.toString()));
		map.put("sign_type", "MD5");
		try {
			wsp.pixNull(PostParam.PAY_API.toString(), map);
			PaySendReqRes.insertSendRequest(map);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * 话费充值描述
	 * @param order
	 * @return
	 */
	public String mobileOrderDesc(Order order){
		String result=new StringBuffer(order.getProdInfo()).append(order.getProPrice())
		.append("元充值[").append(order.getPhonenum()).append("]")
		.append((int)(order.getSalePrice()*100)).toString();
		return result;
	}
}
